package com.tech.arno.spicy.mvp.modelImpl;

import com.tech.arno.spicy.manager.DialogManager;
import com.tech.arno.spicy.manager.UserManager;
import com.tech.arno.spicy.module.user.User;
import com.tech.arno.spicy.mvp.listener.OnLoginFinishedListener;
import com.tech.arno.spicy.mvp.model.LoginModel;
import com.tech.arno.spicy.network.http.RequestCenter;
import com.tech.arno.spicysdk.okhttp.listener.DisposeDataListener;

/*
*   @package:     com.tech.arno.spicy.mvp.modelImpl
*   @fileName:    LoginModelImpl
*   @author:    ArnoFrost
*   @date:  2017/12/21 0021 15:08
*   @desc:     登录业务具体实现
*/

public class LoginModelImpl implements LoginModel {

    @Override
    public void login(String username, String password, final OnLoginFinishedListener listener) {
        RequestCenter.login(username, password, new DisposeDataListener() {
            @Override
            public void onSuccess(Object responseObj) {
                DialogManager.getInstnce().dismissProgressDialog();
                User user = (User) responseObj;
                UserManager.getInstance().setUser(user);//保存当前用户单例对象
                listener.onSuccess();
            }

            @Override
            public void onFailure(Object reasonObj) {
                DialogManager.getInstnce().dismissProgressDialog();
                listener.onError();
            }
        });
    }
}
